package com.zd.wechatPlatform.service.impl;

import com.zd.wechatPlatform.bean.model.WxAccount;
import com.zd.wechatPlatform.dao.WxAccountDao;
import com.zd.wechatPlatform.dao.common.BaseDao;
import com.zd.wechatPlatform.dao.common.FindRequestEntity;
import com.zd.wechatPlatform.dao.common.WhereEnum;
import com.zd.wechatPlatform.service.IWxAccountService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 
 * @author lishi
 * @date 2017-11-29 上午10:47:54
 */
@Service
public class WxAccountServiceImpl extends BaseServiceImpl<WxAccount> implements IWxAccountService {
	@Autowired
	private WxAccountDao wxAccountDao;
	
	public BaseDao<WxAccount> getBaseDao() {
		return wxAccountDao;
	}

	@Override
	public List<WxAccount> findAll() {
        FindRequestEntity param  = new FindRequestEntity();
        return find(param);
	}

	@Override
	public WxAccount getByAppId(String appId) throws Exception {
		FindRequestEntity findReq=new FindRequestEntity();
		findReq.addWhere("app_id", WhereEnum.EQ, appId);
		List< WxAccount> wxAccountList= wxAccountDao.find(findReq);
		if(wxAccountList != null && wxAccountList.size() > 0){
			return wxAccountList.get(0);
		}
		return null;
	}

	@Override
	public WxAccount getByAccountId(String accountId) throws Exception {
		FindRequestEntity findReq=new FindRequestEntity();
		findReq.addWhere("account_id", WhereEnum.EQ, accountId);
		List< WxAccount> wxAccountList= wxAccountDao.find(findReq);
		if(wxAccountList != null && wxAccountList.size() > 0){
			return wxAccountList.get(0);
		}
		return null;
	}
}
